<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2014.07.28.
   家居商家预约参观订单控制器($$)*/

!defined('Q_PATH') && exit;

class JiajubuildorderController extends AController{

	public function filter_(&$arrMap){
		$arrMap['A.jiajubuildorder_realname']=array('like',"%".Q::G('jiajubuildorder_realname')."%");
		$arrMap['A.jiajubuildorder_qq']=array('like',"%".Q::G('jiajubuildorder_qq')."%");
		$arrMap['A.jiajubuildorder_mobile']=array('like',"%".Q::G('jiajubuildorder_mobile')."%");

		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function index($sModel=null,$bDisplay=true){
		parent::index('jiajubuildorder',false);
		$this->display(Admin_Extend::template('jiaju','jiajubuildorder/index'));
	}
	
	protected function sqljoin_(){
		return "->join('".Q::C('DB_PREFIX')."jiajucompany AS C','C.jiajucompany_id,C.jiajucompany_fullname,C.jiajucompany_isfvip,C.jiajucompany_domain','A.jiajucompany_id=C.jiajucompany_id')".
			"->join('".Q::C('DB_PREFIX')."jiajubuild AS D','D.jiajubuild_title','A.jiajubuild_id=D.jiajubuild_id')";
	}

	public function edit($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		parent::edit('jiajubuildorder',$nId,false);

		// 在建工地
		$arrWhere=array();
		$arrWhere['A.jiajubuild_id']=Model::F_('jiajubuildorder','jiajubuildorder_id=?',$nId)->getColumn('jiajubuild_id');

		$arrBuild=Model::F_('jiajubuild','@A')
			->setColumns('A.jiajubuild_id,A.jiajubuild_title,A.jiajubuild_realspace,A.jiajubuild_starttime')
			->joinLeft(Q::C('DB_PREFIX').'jiajucompanyclass AS E','E.jiajucompanyclass_name AS space_name','A.jiajubuild_spaceid=E.jiajucompanyclass_id')
			->where($arrWhere)
			->getOne();
		$this->assign('arrBuild',$arrBuild);

		$this->display(Admin_Extend::template('jiaju','jiajubuildorder/add'));
	}

	public function insert($sModel=null,$nId=null){
		$nId=Q::G('value');
		parent::insert('jiajubuildorder',$nId);
	}

	public function update($sModel=null,$nId=null){
		$nId=Q::G('value');
		parent::update('jiajubuildorder',$nId);
	}

	public function forbid($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::forbid('jiajubuildorder',$nId,true);
	}

	public function resume($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::resume('jiajubuildorder',$nId,true);
	}

	public function clear_recycle($sModel=null,$sField='status'){
		parent::clear_recycle('jiajubuildorder',$sField);
	}

	public function foreverdelete_deep($sModel=null,$sId=null){
		$sId=Q::G('value');
		parent::foreverdelete_deep('jiajubuildorder',$sId);
	}

	public function foreverdelete($sModel=null,$sId=null,$bApp=false){
		$sId=Q::G('value');
		parent::foreverdelete('jiajubuildorder',$sId,true);
	}

	public function orderStatus($status){
		switch($status){
			case 0:// 客户下单
				return '<span style="color:blue;">等待确认</span>';
				break;
			case 1:// 商家确认
				return '<span style="color:#0DD07F;">商家已确认</span>';
				break;
			case 13:
				return '<span style="color:gray;">订单关闭</span>';
				break;
			case 9:
				return '<span style="color:red;">回收站</span>';
				break;
			default:
				return '未知';
				break;
		}
	} 

}
